<template>
	<view class="page-body">
		<!-- 页面内容开始 -->

		<!-- 表格搜索组件开始 -->
		<vk-data-table-query v-model="queryForm1.formData" :columns="queryForm1.columns" @search="search">
		</vk-data-table-query>
		<!-- 表格搜索组件结束 -->

		<view v-if="vk.vuex.get('$user.userInfo.username') =='admin'">
			<el-button type="success" size="small" @click="exportData()">导出数据
			</el-button>
			<!-- 自定义按钮区域结束 -->
		</view>


		<!-- 通过当前用户名来判断，是否展示用户编辑按钮 -->
		<view>
			<!-- 表格组件开始 -->
			<vk-data-table ref="table1" :action="table1.action" :columns="table1.columns" :query-form-param="queryForm1"
				:right-btns="['detail_auto','update','delete']" :row-no="true" :pagination="true" @update="updateBtn"
				@delete="deleteBtn"></vk-data-table>
			<!-- 表格组件结束 -->
		</view>

		<!-- 		<view v-else>
			<vk-data-table ref="table1" :action="table1.action" :columns="table1.columns" :query-form-param="queryForm1"
				:right-btns="['detail_auto','delete']" :row-no="true" :pagination="true" @update="updateBtn"
				@delete="deleteBtn"></vk-data-table>
		</view> -->


		<!-- 添加或编辑的弹窗开始 -->
		<vk-data-dialog v-model="form1.props.show" :title="form1.props.title" width="500px" mode="form"
			:close-on-click-modal="false">
			<vk-data-form v-model="form1.data" :rules="form1.props.rules" :action="form1.props.action"
				:form-type="form1.props.formType" :columns='form1.props.columns' label-width="120px"
				@success="form1.props.show = false;refresh();"></vk-data-form>
		</vk-data-dialog>
		<!-- 添加或编辑的弹窗结束 -->

		<!-- 页面内容结束 -->
	</view>
</template>

<script>
	var that; // 当前页面对象
	var vk = uni.vk; // vk实例
	var originalForms = {}; // 表单初始化数据

	export default {
		data() {
			// 页面数据变量
			return {
				// 页面是否请求中或加载中
				loading: false,
				// init请求返回的数据
				data: {

				},
				// 表格相关开始 -----------------------------------------------------------
				table1: {
					// 表格数据请求地址
					action: "admin/pages/kh/yhsj/yhgl/getList",
					// 表格字段显示规则
					columns: [{
							key: "",
							title: "用户信息",
							type: "group",
							minWidth: 250,
							align: "left",
							columns: [{
									key: "_id",
									title: "用户ID",
									type: "text"
								},
								{
									key: "nickname",
									title: "昵称",
									type: "text",
									defaultValue: "未设置"
								},
								{
									key: "tg_pt",
									title: "推广平台",
									type: "text"
								},
								{
									key: "register_env.os_name",
									title: "用户系统类型",
									type: "text",
									defaultValue: "未绑定"
								}
							],
						},

						{
							"key": "avatar",
							"title": "头像",
							"type": "image",
							"width": 80
						},

						{
							"key": "platform",
							"title": "平台",
							"type": "tag",
							"width": 80,
							sortable: "custom",
							data: [{
									value: "weixin",
									label: "微信",
									tagType: "success"
								},
								{
									value: "tt",
									label: "抖音",
									tagType: "warning"
								},
								{
									value: "ks",
									label: "快手",
									tagType: "error"
								},
								{
									value: "h5-weixin",
									label: "公众号H5",
									tagType: "success"
								},
								{
									value: "h5",
									label: "H5",
									tagType: "warning"
								},
							]
						},

						{
							key: "",
							title: "账户信息",
							type: "group",
							minWidth: 180,
							align: "left",
							columns: [{
									key: "plus_type",
									title: "会员类型",
									type: "tag",
									defaultValue: 0,
									sortable: "custom",
									data: [{
											value: 0,
											label: "普通用户(0)",
											tagType: "success"
										},
										{
											value: 1,
											label: "会员(1)",
											tagType: "danger"
										}
									]
								},
								{
									key: "balance",
									title: "金豆余额",
									type: "number",
									sortable: "custom",
									defaultValue: "0"
								},
								{
									key: "my_invite_code",
									title: "用户邀请码",
									type: "text"
								}
							]
						},


						{
							key: "",
							title: "小程序信息",
							type: "group",
							minWidth: 230,
							align: "left",
							columns: [{
									key: "appid",
									title: "appid",
									type: "text"
								},
								{
									key: "appname",
									title: "小程序名称",
									type: "text"
								},
								{
									key: "wx_openid.mp-weixin",
									title: "wx_openid",
									type: "text",
									defaultValue: "无"
								},
							],
						},

						{
							key: "",
							title: "投放广告信息",
							type: "group",
							minWidth: 180,
							align: "left",
							columns: [{
									key: "aid",
									title: "广告计划ID",
									type: "text"
								},
								{
									key: "ad_id",
									title: "广告账户ID",
									type: "text"
								},
								{
									key: "promotion_id",
									title: "巨量资产化-计划ID",
									type: "text"
								},
								{
									key: "advertiser_id",
									title: "巨量资产化-账户ID",
									type: "text"
								},
							],
						},

						{
							key: "",
							title: "其他信息",
							type: "group",
							minWidth: 200,
							align: "left",
							columns: [{
									key: "tfid",
									title: "投放链接ID",
									type: "text"
								},
								{
									key: "register_env.client_ip",
									title: "用户ip",
									type: "text"
								},
								{
									key: "middleman_id",
									title: "隶属机构",
									type: "text",
									defaultValue: "未绑定"
								},
								{
									key: "middleman_name",
									title: "机构名称",
									type: "text",
									defaultValue: "未绑定"
								},
								{
									key: "invite_code",
									title: "上级邀请码",
									type: "text",
									defaultValue: "未绑定"
								},
								{
									key: "agent_name",
									title: "代理商名称",
									type: "text",
									defaultValue: "未绑定"
								},
							],
						},
						{
							"key": "register_date",
							"title": "注册时间",
							"type": "time",
							"width": 160,
							"sortable": "custom"
						},
						{
							"key": "remark",
							"title": "备注",
							"type": "text",
							"width": 100
						},
						{
							key: "",
							title: "clickid&clue_token",
							type: "group",
							minWidth: 200,
							align: "left",
							columns: [{
									key: "clickid",
									title: "clickid",
									type: "text"
								},
								{
									key: "clue_token",
									title: "clue_token",
									type: "text"
								},
							]
						},
					],
					// 多选框选中的值
					multipleSelection: [],
					// 当前高亮的记录
					selectItem: ""
				},
				// 表格相关结束 -----------------------------------------------------------
				// 表单相关开始 -----------------------------------------------------------
				// 查询表单请求数据
				queryForm1: {
					// 查询表单数据源，可在此设置默认值
					formData: {

					},
					// 查询表单的字段规则 fieldName:指定数据库字段名,不填默认等于key
					columns: [{
							key: "tfid",
							title: "投放链接ID",
							type: "text",
							"width": 150,
							"mode": "="
						},
						{
							"key": "_id",
							"title": "用户ID",
							"type": "text",
							"width": 150,
							"mode": "="
						},
						{
							"key": "nickname",
							"title": "昵称",
							"type": "text",
							"width": 150,
							"mode": "%%"
						},
						{
							"key": "agent_name",
							"title": "代理商昵称",
							"type": "text",
							"width": 200,
							"mode": "="
						},
						{
							"key": "middleman_name",
							"title": "机构昵称",
							"type": "text",
							"width": 200,
							"mode": "="
						},
						{
							"key": "tg_pt",
							"title": "推广平台",
							"type": "text",
							"width": 150,
							"mode": "="
						},
						{
							"key": "platform",
							"title": "平台",
							"type": "select",
							"data": [{
								"value": "weixin",
								"label": "微信"
							}, {
								"value": "tt",
								"label": "头条抖音"
							}, {
								"value": "ks",
								"label": "快手"
							}, {
								"value": "h5-weixin",
								"label": "公众号H5"
							}, {
								"value": "h5",
								"label": "H5"
							}, {
								"value": "quickapp",
								"label": "快应用"
							}],
							"mode": "="
						},
						{
							"key": "plus_type",
							"title": "会员类型",
							"type": "select",
							"data": [{
								"value": 0,
								"label": "普通用户"
							}, {
								"value": 1,
								"label": "会员"
							}],
							"mode": "="
						},
						{
							"key": "my_invite_code",
							"title": "用户邀请码",
							"type": "text",
							"width": 200,
							"mode": "%%"
						},
						{
							"key": "invite_code",
							"title": "上级邀请码",
							"type": "text",
							"width": 200,
							"mode": "%%"
						},
						{
							"key": "appid",
							"title": "appid",
							"type": "text",
							"width": 200,
							"mode": "="
						},
						{
							"key": "register_env.os_name",
							"title": "系统类型",
							"type": "select",
							"data": [{
								"value": "ios",
								"label": "IOS用户"
							}, {
								"value": "android",
								"label": "android用户"
							}, {
								"value": "windows",
								"label": "windows用户"
							}],
							"mode": "="
						},
						{
							"key": "register_date",
							"title": "注册时间",
							"type": "datetimerange",
							"width": 400,
							"mode": "[]"
						},
						{
							"key": "wx_openid.mp-weixin",
							"title": "微信openid",
							"type": "text",
							"width": 200,
							"mode": "="
						},
						{
							"key": "remark",
							"title": "备注",
							"type": "text",
							"width": 200,
							"mode": "%%"
						},
					]
				},
				form1: {
					// 表单请求数据，此处可以设置默认值
					data: {

					},
					// 表单属性
					props: {
						// 表单请求地址
						action: "",
						// 表单字段显示规则
						columns: [{
								"key": "_id",
								"title": "用户ID",
								"type": "text",
								"disabled": true,
								showRule: () => {
									if (vk.vuex.get('$user.userInfo.username') != 'admin') {
										return false
									}
								}
							},
							{
								"key": "nickname",
								"title": "昵称",
								"type": "text",
								showRule: () => {
									if (vk.vuex.get('$user.userInfo.username') != 'admin') {
										return false
									}
								}
							},
							{
								"key": "avatar",
								"title": "头像地址",
								"type": "file-select",
								"placeholder": "请选择图片",
								"fileType": "image",
								"limit": 1,
								showRule: () => {
									if (vk.vuex.get('$user.userInfo.username') != 'admin') {
										return false
									}
								}
							},
							{
								"key": "mobile",
								"title": "手机号码",
								"type": "text",
								showRule: () => {
									if (vk.vuex.get('$user.userInfo.username') != 'admin') {
										return false
									}
								}
							},
							{
								"key": "username",
								"title": "用户名",
								"type": "text",
								"disabled": true,
								showRule: () => {
									if (vk.vuex.get('$user.userInfo.username') != 'admin') {
										return false
									}
								}
							},
							{
								"key": "my_invite_code",
								"title": "用户邀请码",
								"type": "text",
								"tips": "邀请其他人时用的邀请码",
								showRule: () => {
									if (vk.vuex.get('$user.userInfo.username') != 'admin') {
										return false
									}
								}
							},
							{
								"key": "invite_code",
								"title": "上级邀请码",
								"type": "text",
								"tips": "别人邀请此用户时用的邀请码",
								showRule: () => {
									if (vk.vuex.get('$user.userInfo.username') != 'admin') {
										return false
									}
								}
							},
							// { "key": "aid", "title": "广告计划ID", "type": "text", "disabled": true },
							// { "key": "cid", "title": "广告创意ID", "type": "text", "disabled": true },
							// {"key":"openid","title":"openID","type":"text"},
							// {"key":"had_youhui","title":"是否优惠充值","type":"switch"},
							{
								"key": "plus_type",
								"title": "会员类型",
								"type": "select",
								data: [{
										value: 0,
										label: "普通用户"
									},
									{
										value: 1,
										label: "会员"
									}
								],
								showRule: () => {
									if (vk.vuex.get('$user.userInfo.username') != 'admin') {
										return false
									}
								}
							},
							{
								"key": "plus_expire_time",
								"title": "会员到期时间",
								"type": "date",
								"dateType": "datetime",
								showRule: () => {
									if (vk.vuex.get('$user.userInfo.username') != 'admin') {
										return false
									}
								}
							},
							{
								"key": "balance",
								"title": "金豆余额",
								"type": "number",
								showRule: () => {
									if (vk.vuex.get('$user.userInfo.username') != 'admin') {
										return false
									}
								}
							},
							{
								"key": "remark",
								"title": "备注",
								"type": "text",
								showRule: () => {
									if (vk.vuex.get('$user.userInfo.username') != 'admin') {
										return false
									}
								}
							},
							{
								"key": "clickid",
								"title": "clickid",
								"type": "text"
							},
							{
								"key": "tg_pt",
								"title": "推广平台",
								"type": "text"
							},
						],
						// 表单验证规则
						rules: {

						},
						// add 代表添加 update 代表修改
						formType: "",
						// 是否显示表单的弹窗
						show: false
					}
				},
				// 其他弹窗表单
				formDatas: {},
				// 表单相关结束 -----------------------------------------------------------
			};
		},
		// 监听 - 页面每次【加载时】执行(如：前进)
		onLoad(options = {}) {
			that = this;
			vk = that.vk;
			that.options = options;
			that.init(options);
		},
		// 监听 - 页面【首次渲染完成时】执行。注意如果渲染速度快，会在页面进入动画完成前触发
		onReady() {},
		// 监听 - 页面每次【显示时】执行(如：前进和返回) (页面每次出现在屏幕上都触发，包括从下级页面点返回露出当前页面)
		onShow() {
			// if (vk.vuex.get('$user.userInfo.role[0]') != "admin") {
			// 	vk.navigateToLogin();
			// }
		},
		// 监听 - 页面每次【隐藏时】执行(如：返回)
		onHide() {},
		// 函数
		methods: {
			// 页面数据初始化函数
			init(options) {
				originalForms["form1"] = vk.pubfn.copyObject(that.form1);
			},
			// 页面跳转
			pageTo(path) {
				vk.navigateTo(path);
			},
			// 表单重置
			resetForm() {
				vk.pubfn.resetForm(originalForms, that);
			},
			// 搜索
			search() {
				that.$refs.table1.search();
			},
			// 刷新
			refresh() {
				that.$refs.table1.refresh();
			},
			// 获取当前选中的行的数据
			getCurrentRow() {
				return that.$refs.table1.getCurrentRow();
			},
			// 显示添加页面
			addBtn() {
				that.resetForm();
				that.form1.props.action = 'admin/pages/kh/yhsj/yhgl/add';
				that.form1.props.formType = 'add';
				that.form1.props.title = '添加';
				that.form1.props.show = true;
			},
			// 显示修改页面
			updateBtn({
				item
			}) {
				that.form1.props.action = 'admin/pages/kh/yhsj/yhgl/update';
				that.form1.props.formType = 'update';
				that.form1.props.title = '编辑';
				that.form1.props.show = true;
				that.form1.data = item;
			},
			// 删除按钮
			deleteBtn({
				item,
				deleteFn
			}) {
				deleteFn({
					action: "admin/pages/kh/yhsj/yhgl/delete",
					data: {
						_id: item._id
					},
				});
			},
			// 监听 - 批量操作的按钮点击事件
			batchBtn(index) {
				switch (index) {
					case 1:
						vk.toast("批量操作按钮1");
						break;
					case 2:
						vk.toast("批量操作按钮2");
						break;
					default:
						break;
				}
			},
			exportData() {
				that.$refs.table1.exportExcel({
					fileName: "导出数据",
					title: "正在导出数据...",
					pageIndex: 1,
					pageSize: -1, // 此值为-1，代表导出所有数据
				});
			}
		},
		// 监听属性
		watch: {

		},
		// 过滤器
		filters: {

		},
		// 计算属性
		computed: {

		}
	};
</script>
<style lang="scss" scoped>
	.page-body {}
</style>